package de.openkanban.client.ui.presenter;

import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;

/**
 * Callback that handles delete user from contacts request
 */
public class DeleteUserFromContactsBooleanCallback implements BooleanCallback {

	final Canvas source;

	public DeleteUserFromContactsBooleanCallback(Object source) {
		super();
		this.source = (Canvas) source;
	}

	public void execute(Boolean value) {
		if (value != null && value) {

			ListGrid bctg = (ListGrid) source;
			ListGridRecord tr = bctg.getSelectedRecord();
			String contactMail = tr.getAttribute("email");

			if (contactMail != null) {
				PreparedRequest prepReq = new PreparedRequest("user", "contact/remove", "contactMail", contactMail);
				prepReq.sendAsyncRequest(new RemoveContactFromUserRequestCallback());
			}
		}
	}

}
